/*
* Copyright (C) 2020 ~ 2024 chaigec All Rights Reserved.
*
* Author:     chaigec <chaigec@163.com>
* Maintainer: chaigec <chaigec@163.com>

 * Use of this source code is governed by MIT license that can be found in the
 * LICENSE file in the root of the source tree. All contributing project authors
 * may be found in the AUTHORS file in the root of the source tree.
*/

#ifndef MK_RTP_SERVER_POOL_H
#define MK_RTP_SERVER_POOL_H
#include "MkUtil/MkTypes.h"

class CMkEvent;
class CMkEventPool;
class CMkTimer;
class CMkRtpUdpServer;
class CMkRtpTcpServer;
class MkApi CMkRtpServerPool
{
public:
    CMkRtpServerPool(CMkEventPool *pEventPool, CMkTimer* pTimer);
    ~CMkRtpServerPool();

    Uint32 Start();
    Uint32 Stop();

    CMkRtpUdpServer* GetFreeUdpServer();
    CMkRtpTcpServer* GetFreeTcpServer();
    const Uint16& GetBeginPort() const { return m_BeginPort; }
    const Uint16& GetEndPort() const { return m_EndPort; }
    void SetBeginPort(const Uint16& BeginPort) { m_BeginPort = BeginPort + (BeginPort % 2); }
    MkPair<CMkRtpTcpServer*, CMkRtpUdpServer*> GetFreeRtpServer() const;
    MkVector<CMkRtpUdpServer*>& GetVecRtpUdpServer() { return m_VecUdpServer; }
protected:
private:
    CMkRtpUdpServer* CreateRtpUdpServer(CMkEvent* pEvent, const Uint16& UdpPort);
    CMkRtpTcpServer* CreateRtpTcpServer(CMkEvent* pEvent, const Uint16& TcpPort);
private:
    CMkEventPool*                   m_pEventPool;
    CMkTimer*                       m_pTimer;
    Uint16                          m_BeginPort;
    Uint16                          m_EndPort;
    MkVector<CMkRtpUdpServer*>      m_VecUdpServer;
    MkVector<CMkRtpTcpServer*>      m_VecTcpServer;
    MkVector<MkPair<CMkRtpTcpServer*, CMkRtpUdpServer*>> m_VecPairRtpServer;
};



#endif
